package com.group.three.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.group.three.mapper.VideosMapper;
import com.group.three.pojo.Videos;
import com.group.three.service.SelectListVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SelectListIpml implements SelectListVideoService {
    @Autowired
    private VideosMapper videosMapper;
    //查询全部可用video
    @Override
    public PageInfo<Videos> selectListVideo(Long videoId,int page,int size) {
        PageHelper.startPage(page,size);
        List<Videos> videos = videosMapper.selectListVideo(videoId,1,null);
        PageInfo<Videos> pageInfo = new PageInfo<Videos>(videos, page);
        return pageInfo;
    }
    //根据id查询
    @Override
    public List<Videos> selectListVideo(Long videoId,Integer isEnable) {
        List<Videos> videos = videosMapper.selectListVideo(videoId,isEnable,null);
        return videos;
    }
    //根据videoName查询
    @Override
    public PageInfo<Videos> selectListVideo(Long videoId, String videoName, int page, int size) {
        PageHelper.startPage(page,size);
        List<Videos> videos = videosMapper.selectListVideo(videoId,1,videoName);
        PageInfo<Videos> pageInfo = new PageInfo<Videos>(videos, page);
        return pageInfo;
    }

    @Override
    public PageInfo<Videos> selectVideoByStar(Integer star,int page, int size) {
        PageHelper.startPage(page,size);
        List<Videos> videos = videosMapper.selectVideoByStar(star, 1);
        PageInfo<Videos> pageInfo = new PageInfo<Videos>(videos, page);
        return pageInfo;
    }

    @Override
    public PageInfo<Videos> selectVideoByYear(String onYear, String endYear, int page, int size) {
        PageHelper.startPage(page,size);
        List<Videos> videos = videosMapper.selectVideoByYear(onYear, endYear, 1);
        PageInfo<Videos> pageInfo = new PageInfo<Videos>(videos, page);
        return pageInfo;
    }

    @Override
    public PageInfo<Videos> selectVideoByPlay(Integer rank,int page, int size) {
        PageHelper.startPage(page,size);
        List<Videos> videos = videosMapper.selectVideoByPlay(rank, 1);
        PageInfo<Videos> pageInfo = new PageInfo<Videos>(videos, page);
        return pageInfo;
    }

    @Override
    public PageInfo<Videos> selectVideoByCom(String rank, int page, int size) {
        PageHelper.startPage(page,size);
        List<Videos> videos = videosMapper.selectVideoByComment(rank, 1);
        PageInfo<Videos> pageInfo = new PageInfo<Videos>(videos, page);
        return pageInfo;
    }

    @Override
    public Integer updatePlayNumber(Integer videoNum, Long videoId) {
        Integer integer = videosMapper.updatePlayNumber(videoNum, videoId);
        return integer;
    }

    @Override
    public PageInfo<Videos> selectselectVideoByTagId(Long tagid, int page, int size) {
        PageHelper.startPage(page,size);
        List<Videos> videos = videosMapper.selectselectVideoByTagId(tagid, 1);
        PageInfo<Videos> pageInfo = new PageInfo<Videos>(videos, page);
        return pageInfo;
    }
}
